Refactored collision code