Fix for the thumbnail generation routine