add encoding logic