Fix for race condition and directory retrieval bug.