Removing some GLOBAL vars and using dependency injection