initial working scanning code