Added sorting and flags to tree_file.
Added support for new protocol.