LPS-41759 Refactor rebuildTree()
LPS-41759 Refactor tests
LPS-41759 Regenerate