Copied code across from Client.py