The Medici played a central role in Machiavelli's life and works. Until 1494 he lived in a city dominated by them, and from 1498 to 1512 he was employed by a government to which they represented a threat and an alternative focus of allegiance for discontented Florentines. When, after eighteen years of exile, they returned to Florence in 1512, the Medici removed Machiavelli from the chancery and his other posts, but he strove subsequently to win their favor, most famously by dedicating The Prince first to Giuliano de' Medici, an idea he had to abandon, and subsequently to Giuliano's nephew, the younger Lorenzo. These efforts were unsuccessful until 1520, when he finally secured their patronage in the form of a commission from the Florentine Studio, arranged by its head, Cardinal Giulio de' Medici, to write a history of Florence, a book that devotes much attention to the deeds of the family's leading members in the fifteenth century. In Machiavelli's last years, Medici favor brought him several minor government posts and assignments. Little is known of Machiavelli's early connections to the Medici. Apart from the friendship of his father, Bernardo, with the Medici chancellor Bartolomeo Scala, the best evidence for Niccolò's links to the Medici is the poem he addressed to Giuliano, son of the elder Lorenzo. Following the expulsion in 1494 of the Medici regime, which was replaced by the most broadly based constitution in Florence's history, whose core was the Great Council of over three thousand members, and especially during his chancery years from 1498 to 1512, Machiavelli had little to do with the Medici.