improve recover function