Remove invalid elements.