Tidied up javascript in templates.