clean and refactor structur of code gen