def _build_summary(top_sentences, all_sents, max_len, sents_to_add=None):
    """
        Auxillary function for summary building. Attempts to fit as many sentences
        into a summary as possible.
        Specifically, tries to add each sentence to the summary, starting
        from the best one         and making sure to not go over a tweet's length
        Arguments:
            `top_sentences` A list of sentence indices sorted in decreasing order of importance
            `all_sents`     All sentences from the original document
            `max_len`       The maximum length of the summary in characters
            `sents_to_add`  A list of sentence indices already added to the summary
        Returns a tuple containing:
            - The list of sentence indices to be contained in the summary
            - The length of the generated summary in characters
    """
    # Try to add each sentence to the summary, starting from the best one
    # and making sure to not go over a tweet's length
    if sents_to_add is None:
        sents_to_add = set()
        
    summary_size = 0
    for i in top_sentences:
        if i not in sents_to_add:
            full_sent = all_sents[i].text
            new_size = summary_size + len(full_sent)
            if summary_size + new_size <= max_len:
                sents_to_add.add(i)
                summary_size += len(full_sent) + 1 # +1 because of the space/newline between sentences
    return sents_to_add, summary_size