Move scratch variables close to where they're used.