refactor code generator