Compiler: refactoring for improved diagnostics