Added code to refresh the image while being drawn