so, i took the two loops where I was crashing without a reason, plus some required lines, and it seems to work, or at least to work for more iterations than before...
I was "smelling" that it could be a solution but really I cannot theoretically justify it, computer science is not my...