After the Mongols left, King Bela IV faced a monumental task: Hungary become utterly devastated, a quarter to half the population dead, practically all towns and most castles destroyed. A German monk famously lamented: "This year, Hungary, which had existed for three hundred and fifty years, was destroyed by the Tatars". However he could make a couple valuable observations: First most stone castles resisted sieges and survived (at the time most fortifications were either wooden or made from earthwork), second heavy cavalry proved effective against Mongol forces (though its often said traditional European knight tactics failed against Mongols, in Hungary they were the only units that could put up somewhat equal fight and didn't just got decimated outright). The other problem was his strained relation with nobles. In the preceding years he led a policy of restauration, that is to reverse his fathers Andrew II's practice of handing out royal land to barons (powerful group of nobles and their alliances), which he claimed was an "useless and unnecessary" way to gain their loyalty. This is also put forward as one reason why did Mongols enjoy so great success in Hungary: The lack of unity between the king and nobility.
To repopulate the country he invited people from all over (Western) Europe to settle down in Hungary, promising various individual and group privileges - such as free movement, right to purchase land, right to reject military service, right to hold markets, right to elect their own judges, tax excemptions and so on. These people were referred to as hospes (latin for stranger/newcomer) in papers, most of them coming from what is todays Italy ("latins"), Germany ("franks") and Belgium/Northern France ("walloons") - names in quotation marks is how Hungarian records at time referred them. He also allowed cumans to settle down in Central Hungary and live in their own ways (in exchange for their military services), and invited Jews as well - this is the time the first sizable Jewish quarter in Hungary was built. These hospes fuelled a mini-boom in urbanization, with many towns gaining their charter in the period between 1245 and 1270. Another notable group he invited were the Knights Hospitaller - they had some presence before, but now they received the whole of Severin and parts of Burzenland, in exchange for military service, castle-building, populating these lands and training the king's own knights.
He stopped feuding with nobles, established an annual diet, recognized their legal rights to land and handed out estates in exchange for new stone castles (First Council of Lyon in 1245 called out for the same measure of fortification as well). And he too himself ordered the construction of several (notably this is when the royal seat moved from Esztergom to Buda where an entirely new palace complex was built), although the nobility far outpaced him, setting the stage of what Hungarian history calls little kings, oligarchs who barely acknowledged the king and were their own lords in their respective lands - but lets not jump 50 years now.
Because he handed out land royal incomes dropped, to compensate the court increased regalia, fees imposed on customs and mining (among the hospes many were skilled miners and opened new sites which greatly helped royal finances) and issued denarius money with high silver content that faciliated better trade. The financially well-versed Jews were widely employed too. All said the economy was rebuilt and even expanded, the royal treasury enjoyed a nice incoming flow of money and used it to finance new castles and train troops.
For all these deeds, King Béla IV received the moniker The second founder. From ruins his policies and acts managed to repopulate Hungary fairly quickly, made the country richer than before, bustling with many new towns and shiney stone-built castles, protected by a larger reorganized army.