Whenever you catch yourself writing repetitive code all over the place your allarm bells should ring.
There is this rule (I don't know who invented it) that says: If you repeat something three times or more, refactor it.
You are repeating - well - much more.
As I told you on HC you may look at some similar codes there to get ideas.