getting rid of duplicate code in base64 encoding