Old scanner code I wrote. Basis for Sweep.