refactor to use a state monad transformer