Implement improved compare-and-replace algorithm for Store.sync.

This is a "do-over" of #4, this time using tabs instead of spaces (heresy!).