bug fix in event loop