several fixes for restore and cleanup