Support polygon as a closed polyline

Not 100% sure about the logic, this should solve issue #2.