Added shutdown checking