added safe shutdown