Added thread for main loop, but it still works ugly. =(