Refactoring top-level monad stacks