working version for gap affine