more clever encoding