Add flat area detection and the vertex map. In addition, simplify types