Added code generation test and fixed code generation