removed use of globals and implemented class variables