complete decoder implementation