Condensed commonly-used global state into a struct

Global values are now passed around as one struct instead of
as several arguments.
Threading framework should be done