Created distance squared function