fix save function