Rewrite collision detection