reduce use of global variables in image output