made algorithm more efficient by not generating worthless pairs that are more distance units apart from one another