started state machine code, updated related code accordingly