Fixed up the scanning code. Added the setup of the lookup tables