Rewrite template JS to use vanilla JS