Declare temp vars in the closest function scope

All temp vars that were added in a function body are now declared in it.

Ensure we release the temp var after a spread call.