Fixed client nullpointerexception when logging errors
Some refactoring