Base64 encoding that works with Python 3
More Python 3 compatibility fixes