Fixes broken "Add" functionality of replace_or_add

As is, 0.5.1 (and likely earlier) have a bug where the "or add" functionality of replace_or_add does not work at all.

This patch corrects that bug. I think I introduced it during cleanup of this file a few months back.