fixed multi-dimensional distance computation and added 3D plotting
capability