get rid of global client var
simplify and reformat