added restore state function