Re-working the scan function