implemented sorted intersectbed to improve the run time