Moved tree implementation to separate files from tests