Added while loop to keep looking for greater distances when searching
for dirty cells