finished draft of code generation