Implementing collision detection