Implemented main event loop with integrated clock.