Compiler refactoring; final fixes and cleanup