fix type encoding/decoding