Fixed the check for dom existence.