optimized collision detection