Fix codegen for import nodes, via some refactoring.