add two functions to encode