Refactor the find collision algorithm.