Fix value decoding and add tests.