Rewritten all code using lenses, IORef-s and a stack of Reader monads.