Fixing bugs with encoding/decoding logic