With the abolition of the charters of Valencia and most of its institutions, and the conformation of the kingdom and its capital to the laws and customs of Castile, top civil officials were no longer elected, but instead were appointed directly from Madrid, the king's court city, the offices often filled by foreign aristocrats. Valencia had to become accustomed to being an occupied city, living with the presence of troops quartered in the Citadel near the convent of Santo Domingo and in other buildings such as the Lonja, which served as a barracks until 1762.