fixed chdir race condition