The kingdom reached the height of its military power and dominion in the latter half of the 18th century, under the de facto rulers Hyder Ali and his son Tipu Sultan. The latter demolished parts of Mysore to remove legacies of the Wodeyar dynasty. During this time, the kingdom of Mysore came into conflict with the Marathas, the British, and the Nizam of Hyderabad, leading to the four Anglo-Mysore wars, success in the first two of which was followed by defeat in the third and fourth. After Tipu Sultan's death in the Fourth Anglo-Mysore War in 1799, the capital of the kingdom was moved back to Mysore from Seringapatam, and the kingdom was distributed by the British to their allies of the Fourth Mysore war. Part of the kingdom was annexed into the Madras Presidency, another part was awarded to the Nizam of Hyderabad. The landlocked interior of the defeated kingdom of Mysore was turned into a princely state under the suzerainty of the British Crown, with the five-year-old Wodeyar Krishnaraja III as titular ruler and with Purnaiah, who had served under Tipu, as chief minister or "Diwan" and Lt. Col. Barry Close as Resident. The British took control of Mysore's foreign policy and insisted on an annual tribute for maintaining a standing British army at Mysore. Purnaiah is credited with improving Mysore's public works. In 1831, claiming there was maladministration, the British took direct control of the princely state. For the next fifty years, the kingdom of Mysore was under the direct rule of British Commissioners, and in 1831 the city of Mysore lost its status as the administrative centre, when the British Commissioner moved the capital to Bangalore.