The main function of the Market Square was commerce. After the city was destroyed by the Mongol invasion in 1241, the Main Square was rebuilt in 1257 and its commercial role expanded with the Magdeburg rights location of the city by the prince of Kraków, Bolesław V the Chaste. The Main Square was designed in its current state with each side repeating a pattern of three, evenly spaced streets set at right angles to the square. The exception is Grodzka Street which is much older and connects the Main Square with the Wawel Castle. Originally the square was filled with low market stalls and administrative buildings and had a "ring" road running around it. It was King Casimir III the Great who built the original Gothic Cloth Hall and the town hall that filled nearly a quarter of the square. Kraków was the capital of the Kingdom of Poland and a member of the Hanseatic League and the city flourished as an important European metropolis.