Refactored old code in Scan.pm