changed loops to state machine