Updated scoping of some variables.