Fixed bug were connection was not closed