add trap_exit flag for clean shutdown