fixed encoding/decoding and tested it