Fixed some threading issues crashing the program.