implemented restore and fixed bugs when history is empty