improved base64 encoding/decoding