Clean up format and improve shadow-DOM filtering