Factor out code generation for applications