complete decoder with tests