Adding and fixing a bit more of the locking and flow control. Fixed
a race condition on directory creation.