Final restore script.

Made changes so that it works as it should.