Fix main thread problem