Full coding/decoding - working variant