added tests for polygons and fixed bugs