middle of client.py refactor