refactor, add ptree logic