corrected missing index in distance calculation