added the connection read & write handling functions