pe/paths-to-tree refactoring
loop refactorings