import re


def remove_extra_whitespace(text):
    """
    Method used to remove extra whitespaces from the text

    Parameters:
    -----------------
        text (string): Text to clean

    Returns:
    -----------------
        text (string): Text after removing extra whitespaces.

    """

    pattern = re.compile(r"\s+")
    without_whitespace = re.sub(pattern, " ", text)

    # Adding space for some instance where there is space before and after.
    if " ? " not in text:
        text = without_whitespace.replace("?", " ? ")

    if ") " not in text:
        text = without_whitespace.replace(")", ") ")

    return text