Added comments and docstrings to template logic and javascript in templates