Improved main thread implementation