added saving upon exit