Optimized hasSimilarBody function