Reorganize encoding/decoding