def find_keyword_block(words: list,
                       keywords: list,
                       word_threshold = 50,
                       concat = False) -> list:
    
    """Function to find the text blocks of keywords.
    
       words: word tokenized text of pdf (preproccesed)
       keyword: list of synonim keywords (all small case)
       word_threshold: how many words to spread around the keyword
       concat: combine all text blocks accounting for overlapping
       
       return: nested list of text blocks, keyword position and keyword.
    """
    
    
    block_positions = []
    for keyword in keywords:
        # Finding positions of keywords
        list_of_keyword_position = [count for count,word in enumerate(words) if keyword in word.lower()]
        for position in list_of_keyword_position:
            start = position-word_threshold if position-word_threshold>0 else 0
            end = position+word_threshold
            block_coordinates = [start,end,position,keyword]
            block_positions.append(block_coordinates)
    
    # Sorting text blocks by starting position
    sorted_positions = sorted(block_positions)  
    
    # Removing overlaps
    if concat:        
        pre = sorted_positions[:-1]
        post = sorted_positions[1:]
        for count, (pre_block, post_block) in enumerate(zip(pre,post)):
            if pre_block[1] >= post_block[0]:
                # Seperate text blocks by the mean of keyword positions
                border = (pre_block[2]+post_block[2])//2+1
                sorted_positions[count][1] = border
                sorted_positions[count+1][0] = border

    return [[' '.join(words[start:end]),pos,kw] for start,end,pos,kw in sorted_positions]