Preventing bug in Image.IsValid() method