tidy up state machine and work on BEP 9