Refactor directory creation into its own function. Make sure dirs are always present