added ends to all the connections to prevent deadlockling