Fixed some errors with code generation.
Improved on code generation for terms