Fixed threading bug when killing the engine