added state monad implementation