As for the code, do you mean the original? I didn't want to post 1600 lines of code - anyway, in trying to figure out what was going on, I boiled it all down to the example given - which seems to be acting oddly.
Let me use the analogy of visiting a doctor. Posting only a bit of code is like going to the doctor and saying "Here is what is wrong with me, please prescribe something." No Doctor I have ever visited let that pass.
You might be right about the code that is acting up. The trouble is, if you are running out of RAM then the code snippets you are posting may very well be just fine. When a microcontroller runs out of RAM its behavior becomes unpredictable.
Attaching your .pde to a post is an option.
Keep in mind the Mega 2560 only has 8K of RAM. Each string (and variable) you use, consumes RAM. If you are using the Ethernet library that takes a healthy chuck of RAM as well.