Fixed code ordering

Code tried to initialise settings before checking if the folder existed. Therefore trying to write a file in a non existent directory and then crashing before directories could be created.