Add error handling to replicate script

Make script more verbose and check for errors on
important actions.