Optimized get_photos function. Add condense_values function