The town magistrate was established in 1690, while the plans for the new fort were still being drawn up, and one of its documents from August of the same year described the condition of the settlement as "ruinous". Two months later, on 29 October, the Ottoman army suddenly attacked. The attack was repulsed only thanks to a well-organised defense, and the Turks withdrew on 6 November, after a brief siege. The event was a clear lesson that the construction of the fort must not be delayed any further. The first phase of Tvrđa's conversion into a Baroque fortress was based on the plan devised by the engineer Mathias von Kaiserfeld from 1691.