Added improved collision detection