Refactor `findPaths` utility.