Improve tests and fix an edge case when decoding from a stream