revamped state machine to use the new state library