 When Sebuktigin died in 997, however, his two sons Mahmud and Ismail disputed over who should succeed him.Khalaf viewed this as an opportunity to gain territory from the Ghaznavids, and sent his fourth son Tahir to take Quhistan and Badghis in 998.Tahir was defeated in Baghdis by Mahmud's uncle Bughrachuq, although the latter was killed in the fighting.