refactor collision detection to use set