factorization of drawing routine