Rewrote the state monad using the evidence-based factorization.