Watch this Author's files
this is great to learn from, might i also suggest users look at:
Thank you so much for sharing this wonderful code with us.
One small issue though, I found a case where instead of detecting 3 intersections it finds 5. Perhaps it is pathological but let me know if you would like more info.