Partly fixed MATH-1096. The 2D cases seem to work now, but there are still problems with the 3D cases.