added saving and opening for templates, fixed toggle bug