rewriting base encoding/decoding