formalized the rewriting
wip tree conversion