Refactor part the client and the test client