refactor client setup and add comments