Added fix for handling bad images