properly close connection