Fix calling nested shutdown functions [closes #2981]