refactoring for self-hosting code generation