Corrected shutdown sequence for client and main