Correct the shutdown logic, to be Scala wise and consistent