Marathon Petroleum Corp. posted a better-than-expected quarterly profit, helped by lower operating costs and robust demand for gasoline during the summer driving season.

Marathon said it also gained from the $1.28 billion acquisition in December of U.S. natural gas processor MarkWest by its MLP, MPLX LP .

The company's total cost and expenses fell 19.6% during second-quarter 2016, in the three months ended June 30.

However, Marathon said its refining and marketing gross margin fell to $12.82 per barrel (bbl) from $14.84/bbl in the second quarter, mainly due to lower crack spreads, which is the difference between the prices of crude oil and refined products.

Net income attributable to Marathon fell to $801 million from $826 million one year earlier, while earnings per share were unchanged at $1.51.

Excluding an impairment charge of $90 million and other items, the company posted a profit of $1.07 per share in the second quarter of 2016.

Revenue and other income fell 18.4% to $16.79 billion.

Analysts on average were expecting earnings of 97 cents per share on revenue of $16.89 billion, according to Thomson Reuters I/B/E/S.