towards librarization - get rid of all globals, put them in a struct instead (huge diff, no logical changes)