fix bugs: race conditions in naming files; inconsistent directory names