converting StreamEngine to state machine