updated with distance squared optimization