move handlers of state machine to function 'sm_run'