first pass at integrating state machine