Added error checking for server and client