Remove the "tree" API and clean up flow a bit

r? @metajack