Switch to use the state monad