adding flag to terminate handler