Fixed bug on closing connection