Adding parameter checking, defaults for 3D; cleanup too