Added flattenTriangular function and test