caught an error in definitnig vars inside a function. Fixed