restructured again while loops without losing context, using first successful 'store' source in restore