Fixed crashing issues due to threads + shared_ptr