Overhaul of the temp_folder() function + use scoped pointers for global objects.