Add error dialog if problems occur during replace. Add a few more unit tests and behavior for edge cases.