Changed patch function object to pure function flattenTree.