Changed how the threading works

The thread can be restarted again once it has been paused.
Clean up some code
More cleaning
Adding comments
Threading