Event loop implementation