Territorially, Muhammad consolidated his realm and gained several strongholds in the Kingdom of Jaén, including Quesada and Alcaudete. He lost Tarifa to Castile, and from this point the town would never again be in Muslim hands. The internal threat from the Banu Ashqilula was eliminated, and Muhammad not only saw off successfully the repeated Marinid attacks, but deprived them of their holdings in Al-Andalus as well. Muhammad oversaw a large-scale fortification project for the kingdom's defences, building a series of strategically positioned and well-supplied strongholds from the west to the east, which formed the backbone of Granadan frontier defences in the centuries to come. He worked with his own hands during the constructions of the moat ("khandaq") in Alcaudete. The fortifications that he built also served to enforce royal authority because they were controlled by military governors ("qa'id"s) appointed and rotated by the court rather than by hereditary lords. They were often located in mountainous or other areas that were difficult to reach, and could only be conquered or breached by expensive siege warfare.