Fixed ensureDirectoryExists