Fix Scan.Close and organize variables