Eliminating graphics (g) as global variable