Made the event handler smarter by only checking events until the next-possible event is hit.