impl and tests for Trees API