Refactor check for empty string when traversing the path.