revert previous fix and fix properly
properly output restore code