moving variables from global to local scope