encode using functions