Move more JS out of templates