added logging, refactored global variables