Refactored Scan.pm; major performance improvements