Adding checks to detect lost packets
Adding capability for closing connection