Large refactoring to encompass extra global passes.