working through state machine code