Code? At least for subroutine changing the main loop progress, is it a Gosub or real Sub?
I bet you are using a Gosub and it is messing with main loop variables.
I bet you are using a Gosub and it is messing with main loop variables.
b = b + ...