fixing finite state machine bug