client.py refactoring and cleanup.