Refactor client code, add comments.