Created an angular directive and moved all of the DOM manipulation over to it