Refactored out common checkDOM code.