Firstly, have you now removed the remnants of the gosub method? They may be interfering, and causing memory location issues.
If it still doesn't work, create yourself a debug file. At the very simplest level, open the file at the beginning of your program, and close it at the end. In between, write lines out to it to establish where you got to, and the state of any important parameters.
Longer term, make yourself a set of debug functions to manage debugging output to a file. It may take a couple of hours now, but save so much more time later.