a few fixes

Mostly a fix for base64 encoding and some fixes for a bit less memory leaking.