Changed base64 to be consistent in line termination
Refactoring and bugfixing