Added flattenTriangular function and test

I removed the check and put the requirement in the comments. If it's a problem later we can change all the helpers to add checks.