Improved collision code.