get rid of global variables, create functions with parameters to be re-used