fix incorrect variable name
local-ize a few more functions
get rid of an excess print() call
local-ize a few more variables and functions