Improve the JPEG handling strategy