Added locks and dummy thread functions. Also moved the delete's around
so they are efficently used for when things go wrong
Moved the loading functions to its own cpp file. The use for this is
that thread function can be kept in its own file. So the main program
is very less clutered