FIx a bug in sort-then-add/remove operation.

This fixes Issue #18.