fixed save function