added test for restore and fixed a related bug