Code cleanup

Moving XML token creation and parsing from NewClient() to helper
functions. NewClient() has now a readable flow.