Refactored JPEG header check