Fixed bug that occurs on connection close