Added most of the server communication code