Program freezes after a while

When the code is rewritten and better readable (and you post it) I will have a 2nd look