Added gracefull shutdown