Malaysia has done the right thing in its surprise announcement tonight that it will send a diplomat and warrant officer back to New Zealand to face sex charges.
The conduct of Malaysian Foreign Minister Anifah Aman since the issue came to light has gone some way to restoring the country's reputation and so will the decision.
For a couple of days, its reputation was dented here when it was wrongly believed the country had whisked the accused diplomat out of New Zealand and thumbed its nose at NZ requests to revoke his diplomatic immunity.
That was down to a bungle by a mid -grade official in the protocol division of the New Zealand ministry who led the Malaysians to believe the New Zealand Government would not object to that course of action. Now MFAT's reputation is dented.
The Malaysians made the decision under a false understanding.
Now that they know it was false, they have reversed their decision.
It may have been as much for domestic reasons - it was starting to become a hot political issue in the hands of Opposition leader Anwar Ibrahim and activist women in Malaysia.
But it is also shows integrity.
The personal consequences of today's decision by Malaysia will no doubt be profound for the victim.
Despite assurances there is no way Zealanders could expect to have confidence in a justice system they know so little about - apart from the fact it imprisons Opposition leaders and still carries out whipping.
The prospect of having to relive an alleged sexual assault would be hard enough but the possibility of having to re-live it in the accused's country must have been daunting.
It would be too much to say it has restored relations with New Zealand because at a political level, they were not damaged in the first place. Malaysia and New Zealand have become a lot closer in recent years: they signed an FTA in 2009, New Zealand joined the East Asia Summit and has made closer relations with Asean a top priority in the region.
Even if the accused, Muhammed Rizalman Bin Ismail, had not been returned, the bilateral relationship would not have been strained by it because it was New Zealand's bungle.
But that's not to say there has been no damage.
Foreign Minister Murray McCully had to apologise to the Prime Minister for allowing him to effectively criticize Malaysia without knowing all the facts, and Foreign Affairs chief John Allen has had to apologise to McCully for not supplying all the facts and, no doubt the protocol division has apologized to Allen.
What is unbelievable is that diplomatic immunity, an issue of such public sensitivity that effectively allows diplomats to get away with murder, is dealt with by the protocol section of the Ministry of Foreign Affairs and Trade and not at least deputy secretary level.
Every case is a potential mine-field.
One of the long-lasting consequences of this episode is that it will undermine the public's confidence in the ministry's competence.
It has already undermined the confidence held by the minister and Prime Minister.
Like the GCSB spy agency, much of MFAT's work is done out of public view. It escapes a lot of scrutiny all in the name of the national interest. It's a ''trust-me" type of operation.
Someone who should not have had the authority to do so, has made it appear that keeping Malaysia out of the papers was more important than New Zealand's interest or perhaps, in some misguided way, they thought that New Zealand's interests were best served by keeping it all quiet.
A review is being undertaken on why the Malaysians got the wrong message, and why Key and McCully were not informed about it before making their public utterances.
Whatever the outcome it may take some time to restore trust in MFAT.