By the nineteenth century, when the Ottoman Empire was in full decline, the Janissaries appeared to many observers to be a weird and obsolete institution that was blocking the ability of the Turkish empire to modernize. They deposed Sultan Selim III in 1807 and elevated Mahmud II to the throne the following year. Mahmud II consolidated his position over the following years, and in 1826 he had the entire corps of Janissaries, some four thousand strong, killed by setting fire to their barracks.