Added base64 decoding
Cleaned up and documented the code