Moved variable 'type' declaration to outer function scope.

Doing this against my conviction in order to settle #980. Would much
prefer to move variables to the inner-most scope instead.