Refactoring in client.py.