added more event processing and cleaned up comments