Big refactoring to handle event-based state better