Some fixes to image loading