Fixed errors with threads that would cause a fatal crash