Rewrite to run straight from the DOM