Fixed client not being properly closed