Refactors the rootPath logic to use the actual base element.