replace global variables with a struct that can be passed around
replace global variables with a struct that can be passed around