Split code generation and loading into separate functions