move code into class to avoid use of Globals.