Copied more code from Client.py