During the realm of the Sultanate, Melaka was an important trading port and the maintenance of law and order was crucial to its prosperity. The administration of justice was placed under the direct charge of the "bendahara" (or chief minister) who exercised both political and judicial functions. The "temenggung" (which is the commander of troops and police) was responsible for apprehending criminals, maintaining prisons and generally keeping the peace. The welfare of foreigners residing in the state was looked after by several "shahbandars" (harbour masters and collectors of customs).