Uses temp_data struct to make code a little cleaner.