many changes, added reset state machine