Fixed a bug in image refreshing