Yes, the best thing you can do is strip down your project until the bug disappears. This way you will know what EXACTLY is causing it.
(!First make a copy!)

And by the way, pushing functions down in a file doesnt change the order they get executed.
Its the place where you're calling the function that matters. And its probably in a while loop or attached to a button. This way, you can never know when the function will get executed, because the user has to click somewhere to do it...

Just strip down everything piece by piece, start with commenting function calls and features of your project, and see where the bug disappears. Its a lot of work, but you have to be prepared to do it in order to move forward with your current project.


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201