Refactore consecutive collision detection code