partially working encode