The revving when you were halfway through the tank was probably small bubbles in the fuel line.
If you think about it, running lean gives you higher RPMs. You run a car leaner by having more air and less fuel in there.
If you have bubbles in the fuel line, or if you're on the last few drops of fuel, then you have more air getting through