added simple event loop code