Refactor some client code