Use scratch variables where appropriate.
Fix tests.