Added state machine to make logic interactive