Broke the logic for codegen for read and write phases apart to accomodate multi-phase transformations