bug fixes, making sure both sides know a connection is being closed to prevent data from being abandoned