fixed a bug with the main thread