Hello.
There is several possible reasons, but for the final answer it's necessary to see the whole code. Also, a remote debugging (using TeamViewer) is the fastest way to check it.
In the meantime, I see several places in your code which can cause such efect.
The main reason, as I can see now, it's wide usage of "String" and lot of text ("i mean this") which can cause the very quickly than your device is out of RAM.
The String() function is good when you need to write "hello world", but for larger projects it quickly causes lack of RAM (and usually this, in sequence, cause resets in very unexpected places).
I can provide a cosultations and help in coding and propose changes in the code with some tricks and several handy functions. But I suppose such changes have to be applyied not only to this fragment of code.
If you like - we can continue after creationg of the project and a single milestone deposite.
Using of Skype and TeamViewer after that can make the whole process much more comfortable for the both sides.
My bid includes 1-2 hours of work, think that's enough to fix all that moments.
With best regards.
Maxim