Fix error in sq_to_dist function