Fixing nearest uncommon directory algorithm, just to be sure infinite loops won't happen.