Lot of duplication here and below. Can we move it out of the if loop and create the transforms at the same time at the top?