Fixed the problem with sorted being incorrectly unfolded in the sorted-flatten example. All tests pass.