Use switch instead of if for event loop.