Modernize code, ensure clear button is always active even when the document is invalid