implementing collision detection