added check for degenerate triangles