Added duplicate and degenerate edge checking.