moved event loop into a thread