Move client.close() to finally