moved intersection test into a function