Torus Distance function fixed (forgot some cases)