removed use of global variables; comments