Simplified tree selector logic, removing duplicate code and outsourced API calls to APIcalls.