used Control.Monad.State Module to implement the state function