Replaced distance function with built-in vector distance calculation