Working base64 implementation, error checking