refactored intersection test loop