fix bug with rotations near borders