Modify scan function to keep track of scan of current row and column