cleanup of events and better state handling
fixing merge conflict