Made a few small changes for clean shutdowns