First version of encoding function...