restructuring recoding loop