fix bug that caused wrong results on not-root dirs.