Fixed some variable scopes