tidied context drawing code