Completed scan function to give result at EOF