timing the scanning loop