Re-apply r84295, with fixes to how the loop "top" and "bottom" blocks are