Rewrote lookups to use the same code as the CSV generator.
Minor fixes.