fixed crash when pressing stop
fixed consecutive dead lock when closing the window