From runaway losses to profit, the company slashed unaccounted gas, rebuilt networks, stabilised its finances.