Refactor collision detection