updated state machine and some bug fixes