Closing connection correctly