Refactorization.
Switched from Reader monad to State monad. This is to make the memo feature possible later.