Properly close connection