Added shutdown logic (just as a safety)