fixing thread safety stuff, going to sleep