Revert "bug 964: Reduce variable scope where possible"

This reverts commit 387fde16ca52b6ccfc5a46be99219cd09a7411ce.
Decision based on discussion with Michael Tänzer.