cleaned up code for thread-derailed