refactor the collision handling