Klaipėda Castle is first mentioned in a document from 1252, in which Grand Master Eberhard von Sayn agreed with Bishop Heinrich of Courland to build a castle between the Nemunas and the Danė. The city began to develop after a wooden castle was built on the Southern Horn of the Danė river. It was believed that the lagoon was a branch of the Nemunas river, called the Memel in Germany, so the castle was named Memelburg. The wooden castle was built on boggy ground, so in 1253 a masonry castle of the enclosure type was built on the right bank of the Danė. Masonry and wooden buildings stood in the castle courtyard, and the walls were protected by moats and ramparts. In the 14th–15th centuries Klaipėda Castle had to withstand numerous attacks by Samogitians and Lithuanians, so it was burned and rebuilt many times. In the 15th century the castle was strengthened so that it could defend itself against firearms. Its defensive system consisted of towers, a defensive wall, moats and ramparts with defensive structures. In the 17th century the Swedes attacked Klaipėda Castle and several fires ravaged it, so its defences had to be rebuilt and improved again. Thus in 1686 the earthen ramparts around the castle were reconstructed into bastions. The last fortification works on Klaipėda Castle and the city took place during the Seven Years' War (1756–1763).