updated for precise collision detection