fixed issues with shutdown and added some error checking