added friendly shutdown