Like motorists, Sunoco Inc. worries when crude prices soar, as they have in 2007.

The Philadelphia company, which dates to the 19th century, long ago sold its oil exploration and production businesses. So it pays for the crude delivered to its refineries, by ship or pipeline, and feels financial pain when there's a lag between a rise in crude and the market price at the pump.

"It has been perhaps one of the most volatile years I've seen," said John G. Drosdick, 64, Sunoco's chief executive and chairman since 2000.

The refiner and marketer has tried to ride out the turbulence by taking over competitors, reducing unscheduled shutdowns with major upgrades at its Philadelphia facilities, and diversifying into chemicals. Those moves, along with the tight refining capacity nationwide, have enabled it to stay in the black even as crude prices have edged toward $100 per barrel.

It's been a tough ride recently. In its third-quarter results, Sunoco said net income fell 38 percent from the same period a year ago. For the nine months ending Sept. 30, its earnings were up 5 percent compared with leaps of 25 percent and 61 percent in previous years.

Refining, on balance, has been good for Sunoco. For 30 years, Sunoco and other refiners had to jostle for advantage because the nation, even though no new refineries were being built, had too much capacity.

That's no longer true.

The United States now burns an average of 1.5 million barrels more fuel daily than it can refine, which means Sunoco can sell every drop it makes. The nation is, for the first time, importing large amounts of refined fuel daily.

While this is good for Sunoco and other refiners, it is expensive for consumers and fleet operators, particularly when the dollar weakens and it takes more of them to buy a barrel.

Sunoco, the region's largest refiner, with more than 4,300 employees, says it saw this coming. Over the last 15 years, it bought local refineries from Arco, Chevron and El Paso Corp. It has been linking them to work together in ways that increase output by reducing the impact when sections are taken down for maintenance or repairs.

Fundamentally, said Vince Kelley, senior vice president for refining, "our focus has shifted from things beyond our control to things we can control - improving safety and reliability and optimizing output."

Sunoco, for example, has built a big control center in Philadelphia that allows it to tweak the variety of products produced, as market prices fluctuate, to yield higher profit.

One wall has 10 jumbo television screens that give an overview of every process in the 1,000-acre Philadelphia complex. From clusters of computer terminals, workers manage each refining step, communicating by radio with workers at the units.

Sunoco is converting an idle cracking unit to upgrade heating oil to ultra low-sulphur diesel fuel, which commands a higher price.

The control center also includes new approaches to safety and reliability. If an operator feels groggy or stiff, there's an exercise area overlooking the control room with an array of workout equipment.

Sunoco also emphasizes safety training, all part of the strategy to minimize shutdowns and losses. At a cluster of consoles used for training, Rickey Small, a 20-year refinery veteran, is harvesting data from operations to create training simulations.

"You could sit out there for months and months and never see anything like this," Small said as he tapped a few keys, triggering a sequence of alarms and a growing crisis on the training screens.

Looking on, W. Roger Lyle, vice president over Sunoco's Philadelphia area refineries, said "refinery work is 80 percent routine, 15 percent problem-solving and 5 percent terror. This [the simulations] could take out the terror."

Sunoco also has been modifying its refineries to broaden the range of light, sweet crude oils it can process, giving it more sources of oil that add up to seven million more barrels available daily.

And it is shopping to buy refineries able to process heavier, sour crudes, which are more abundant.

With light, sweet crude expected to average $85 per barrel in 2008, the discounts available for buying heavier crudes make it economically feasible to cover the extra cost of refining it, said Dwight Wiggins, principal of Silver Eagle Energy L.L.C., a consulting firm with no connection to Sunoco.

Sweet means the crude has a low sulphur content; light means it is more liquid. This translates into a less costly refining process. Sour Venezuelan crude is high in sulphur and is so thick it "becomes solid at room temperature. You could lay a brick on it and it wouldn't sink," Wiggins said.

Several projects are under way to increase the nation's refining capacity and reduce imports, which could blunt Sunoco's edge. Motiva Enterprises L.L.C., a joint venture between Shell Oil Co. and Saudi Refining Inc., this month began work on expanding its Port Arthur, Texas, facility. The $7 billion project will more than double its capacity to 610 million barrels per day, surpassing the ExxonMobil Corp.'s Baytown, Texas, refinery as the nation's largest.

Sunoco declined to predict when U.S. refining capacity will catch up with demand. Drosdick, the CEO, would say only that the tight capacity that benefits his company will last at least three more years.

Wiggins, the refinery executive-turned-consultant, said the United States will have to do a lot of refinery building to keep up with increasing demand.

On paper, the United States can refine 16.5 million barrels daily, and the demand often exceeds 18 million barrels, said Wiggins, former president of Tosco Refining Co., which had eight refineries, including one in Trainer, Pa., when the company was acquired by ConocoPhillips Co.

To keep pace with even conservative estimates of fuel consumption growth, Wiggins said the United States will need one project the size of the Motiva expansion every year.

It is difficult to forecast the cost to consumers of this tight capacity. But it could be high if a disaster, like Katrina in 2005, shuts down refineries.

And some experts worry that many refineries have deferred maintenance to make up for capacity knocked out by Katrina. This could lead to more shutdowns in the coming year and increase the nation's need for costly imported refined products. If demand exceeds capacity of short-haul import sources in Canada, more will have to come from expensive distant sources in Europe.

Sunoco said it has kept its maintenance on schedule and expects to keep reducing the time between unscheduled shutdowns.

Sunoco also has tried to cushion oil-price shocks by expanding its chemical business, but it so far generates only about 3 percent of the company's revenue.

"We're not going to sell it just to sell it," Drosdick told equity analysts recently.

He said Sunoco has developed more ingredients for chemical products than its rivals have. "We're looking for ways to put our assets together with someone else's."