def stripAndRemoveNewlines(text):
    """Removes empty newlines, and removes leading whitespace.
    """
    no_empty_newlines = "\n".join([ll.rstrip() for ll in text.splitlines() if ll.strip()])
    return no_empty_newlines.strip()