Completed rewrite of restoration code