<prompt> Translate the following text to EnglishAliwahi kuwa Seneta wa jimbo la Massachusetts na Seneta wa Marekani, na kisha, wakati wa urais wa James Monroe, kama Katibu wa Jimbo, ambapo alikuwa na jukumu kubwa la kutunga kanuni za nyuma ya Dokta ya Monroe.  <response>: He served as a Massachusetts state senator and a U.S. senator, and then, during James Monroes presidency, as secretary of state, where he was largely responsible for formulating the principles behind the Monroe Doctrine. 