The screenplay was written by Fran Walsh, Philippa Boyens, Jackson, and Guillermo del Toro, who was originally chosen to direct before his departure from the project. The films take place in the fictional world of Middle-earth sixty years before the beginning of The Lord of the Rings, and follow hobbit Bilbo Baggins (Martin Freeman), who is convinced by the wizard Gandalf the Grey (Ian McKellen) to accompany thirteen dwarves, led by Thorin Oakenshield (Richard Armitage), on a quest to reclaim the Lonely Mountain from the dragon Smaug (voiced by Benedict Cumberbatch). The films also expand upon certain elements from the novel and other source material, such as Gandalf's investigation at Dol Guldur, and the pursuit of Azog and Bolg, who seek vengeance against Thorin and his ancestors.