first implementation of state monad