Refactor tree_util.d