improved selection of path. Big refactoring