added code to deal with connecting to the server