with state restoration and NSUserDefault