def spell_correct(args, gb, gb_and_pwl, word, bigrams):
    """
        Function to spell-check a word and correct it if possible.

        input:
            args (argparse object): input arguments
            gb: british dictionary for spell checking
            gb_and_pwl: words from british dictionary and input personal word
                list
            word (str): word to spell-check
            bigrams (dict): corpus bigrams read from args.corpus_bigrams

        returns spell-checked (and corrected, if necessary) word
    """
    # If the line is a valid word, continue
    if word == "" or word[0].isupper() or gb.check(word): return word
    else:
        # Suggest corrections for sub_line
        suggestions = gb_and_pwl.suggest(word)
        # See if any of them are reasonable
        options = []
        for opt in suggestions:
            l = opt.split()
            if len(l) == 2 and "".join(l) == word:
                options.append(opt)
                break
        # Find the most probable option
        best = (word, 0)
        for opt in options:
            try:
                # Check if option is a bigram that appears in corpus
                if bigrams[opt] > best[1]: best = (opt, bigrams[opt])
            except KeyError: continue

    return best[0]