This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
TL;DR It might help if you posted some more information, like what it should do, what it doesn't do and what it does instead. And you may want to condense all this code into an SSCCE that shows the problem.