For me it's hard to tell what's wrong without more description of the mis-behavior and without seeing a bit more of the code.

From a practical coding standpoint, if this were my program I'd...