Refactors collision handling into separate function