Finished IR generation and refactored some code.