The first action taken by the Cid was to eradicate the influence of the counts of Barcelona in that territory. When Berenguer Ramon II was humiliatingly beaten at Tebar, near Teruel, this was done (May 1090). During the next years, the Cid increasingly strengthened his grip on Valencia and its king, al-Qadir, who was now his subject. He imposed taxes on the city's inhabitants and revenues from mines. El Cid began as a military leader but soon established himself as an administrator and politician. He introduced legislation into the local assembly which granted equal rights to citizens regardless of class or religion. He also built many hospitals for sick people without money enough to pay doctors. He gave jobs to unemployed people, raised wages, and reduced prices for goods. All this made Valencia one of the most prosperous cities of Europe at that time. When al-Qadir died in 1104, the new king's brother, Arnau Roger, wanted to get rid of the Cid but failed because of the popular support he received. So, he decided to compromise by making the Cid prince of Valencia instead. The Cid agreed and was made ruler of all the territories held by the viscounts of Béarn. As prince, the Cid continued to fight against the counts of Barcelona but also took part in several campaigns against other opponents such as Alfonso VI of León and Castile.