Merge in Jake's work and move into switched state machine inside infinite loop. Untested..