improve state machine for readability