Fixed more threading issues. The main thread now sets up the window and runs the main event loop.