fixes brought over from Wayne's 3D version

CPU and CUDA versions work