pseudo-working encode function