Refactored event-loop.