added StateMachine and calibration logic