Reworked affine transformation