Greatly improved replica.py script

* Streamlined the code substantially
* Passes pylint and pep8 linters
* Handle errors a little better
* Ensure the auto-snapshot setting is restored