Implemented most of code generation