add event loop code