Improve by splitting out DOM-manipulating code into its own directive