update Flowchart algorithm: handle sub-trees better