Refactored auxiliary functions in MX codegen, #169