split up scan.php, stage 1 - 3