encode functunality