refactor client code