fix some bugs in image loading
added comments