Fix save function