More encoding/decoding and test clean up