change intersect to a free function