split up scan.php, stage 4