Extracted out collision handling into its own function.