refactoring: updatePath() as separate function