changed save function