Implementation of scanNext()