added die_gracefully function