added saving mechanism