Refactored collision handler.