JPEG: refactor