state machine implementation for events