move local vars in functions  to script level