Added the restore code

Added the restore and added more comments.