refactoring, now start to prepare the event loop