Improvements of 3D motion correction

Various bug fixes and enhancements. 3D motion correction now appears to work well.