Fixed some bugs in the main thread.