Refactor the checkCollisions