Refactoring with the Hell monad