State monad version and prettification macros all seem to work now.