Fix encoder, add a couple tests.