Refactored code generator and fixed a number of bugs were assembly code