algorithm for collision bug cleared