Added code to automatically create missing directories.