If you want help, you'll have to provide an SSCCE that demonstrates the problem.

Alternatively, you should step through this with a debugger or at the very least add some print statements to...