Before Spanish colonization, the Philippines was made up of independent barangays that functioned as city-states or principalities. Barangays were coastal or riverine communities usually numbering between 50-100 families ruled by a datu. Larger barangays in places like Cebu, Manila and Butuan were cosmopolitan principalities with established social hierarchies and trade relations. The barangays had complex social structures divided into nobility classes like the tumao and warrior classes like the timawa. Upon colonization, smaller barangays were combined into towns headed by a cabeza de barangay under Spanish rule.