Added two passes for polygon merging