Simplified tree file and separated concerns.

This is not currently fully working.
Added sorting and flags to tree_file.
Added support for new protocol.