and make them a bit more concise. No functional changes
Both for just encode function as well as an end-to-end test.