optimize collision detection