fix reordering bug

adding a failing test that shows that reordering goes wrong when swapping an item with the last item.

/cc @elhornair