Added crash and shutdown handling