Changed the way the connection is closed