Adding code to automatically create directories if they don't exist