In 1349, the Kingdom of Ruthenia with its capital Lviv was annexed by the Crown of the Kingdom of Poland. The kingdom was transformed into the Ruthenian domain of the Crown with Lwów as the capital. On 17 June 1356 King Casimir III the Great granted it Magdeburg rights. In 1362, the High Castle was completely rebuilt with stone replacing the previous made out of wood. The city's prosperity during the following centuries is owed to the trade privileges granted to it by Casimir, Queen Jadwiga and the subsequent Polish monarchs. Germans, Poles and Czechs formed the largest groups of newcomers. Most of the settlers were polonised by the end of the 15th century, and the city became a Polish island surrounded by Orthodox Ruthenian population.