Added ability to do a clean shutdown while connecting