better conditional base64 encoding