changed order of code gen to a predictable order