Fixed a bug in the intersection function