state monad implementation
monad stack implementation