In the 12th century the first foundations of a castle were established, with the construction of a round tower for guard and lookout. The tower was continuously expanded in the 13th century, and as such, Queen Margaret called an assembly there between the heads of state of Sweden and Norway, and on 13 July 1397, the Kalmar Union treaty was signed, which would last until 1523. Kalmar's strategic location, near the Danish border (at the time the Scanian lands, i.e. the provinces of Blekinge, Halland and Scania, were part of Denmark), and its harbour and trade, also involved it in several feuds. There are two events independently labelled the Kalmar Bloodbath, 1505: the first in 1505, when King John of Denmark, Norway, and Sweden had the mayor and city council of Kalmar executed; the second in 1599 by command of Duke Charles, later to become King Charles IX of Sweden.