minor changes to variable scope