Add nil check for immediate shutdown