bugfixes in polygon, some documentation and cleanup