It's hard to know what's happening without more code.

What I would do is add trace functions throuout this piece of code. This way you know which parts are exceuting and which aren't.

From that...