set up paint method to avoid flickering