Put all collision detection into its own function.