Merge "Misc. refactoring of loop restoration" into nextgenv2