refactoring: get rid of almost every "global" variable