fix state machine, make bugs fewer

next step is for BLE