Fixed the connection closing bug