Create a function for encode