factored out polygons, but still buggy