improve encoder, and add base64 output which is often better