The Sikh Confederacy (1748–1799) was a group of small states in the Punjab that emerged in a political vacuum created by rivalry between the Mughals, Afghans and Persians. The Confederacy drove out the Mughals, repelled several Afghan invasions and in 1764 captured Lahore. However, after the retreat of Ahmed Shah Abdali, the Confederacy suffered instability as disputes and rivalries emerged. The Sikh empire (1799–1849) was formed on the foundations of the Confederacy by Ranjit Singh who proclaimed himself ""Sarkar-i-Wala"", and was referred to as the Maharaja of Lahore. His empire eventually extended as far west as the Khyber Pass and as far south as Multan. Amongst his conquests were Kashmir in 1819 and Peshawar in 1834, although the Afghans made two attempts to recover Peshawar. After the Maharaja's death the empire was weakened by internal divisions and political mismanagement. The British annexed the Sikh Empire in 1849 after two Anglo-Sikh wars. The British Raj ruled from 1858 to 1947, the period when India was part of the British Empire. Following a major mutiny, the British took steps to avoid further rebellions taking place including changing the structure of the Army. They banned Indians from the officer corp and artillery corp to ensure that future rebellions would not be as organised and disciplined and that the ratio of British soldiers to Indians would be drastically increased. Recruiting percentages changed with an emphasis on Sikhs and Gurkhas whose loyalties and fighting prowess had been proven in the conflict and new caste- and religious-based regiments were formed. During World War I the British Indian Army fought in Egypt, Palestine, Mesopotamia, Gallipoli, and France and suffered very heavy casualties. The British Indian Army's strength was about 189,000 in 1939. There were about 3,000 British officers and 1,115 Indian officers. The army was expanded greatly to fight in World War II. By 1945, the strength of the Army had risen to about two-and-a-half million. There were about 34,500 British officers and 15,740 Indian officers. The Army took part in campaigns in France, East Africa, North Africa, Syria, Tunisia, Malaya, Burma, Greece, Sicily and Italy. It suffered 179,935 casualties in the war (including 24,338 killed, 64,354 wounded, 11,762 missing and 79,481 soldiers). Many future military officers and leaders of Pakistan fought in these wars.