The consolidation of Bhutan occurred in 1616 when Ngawanag Namgyal, a lama from western Tibet known as the Zhabdrung Rinpoche, defeated three Tibetan invasions, subjugated rival religious schools, codified the "Tsa Yig", an intricate and comprehensive system of law, and established himself as ruler over a system of ecclesiastical and civil administrators. After his death, infighting and civil war eroded the power of the Zhabdrung for the next 200 years. In 1885 Ugyen Wangchuck was able to consolidate power, and began cultivating closer ties with the British in the subcontinent.