unified decode logic.