Yes, that’s right but can you think of any reason for the bug? Or any possible solution to try?
Yes, try stepping through this code with the debugger on both the working version and non-working version and then compare the behaviour to see what is going on. Specifically locate the point at which their behaviours diverge.