refactoring + state machine event system