Split out the directory fix
Moved the setup function up to group the logging and saving functions