fix intersection algorithm