restored affine code because upside in the repo is bad