fix some bugs in image extraction