Extending removeFromRealm() to be able to remove last object

As reported in #595 `removeFromRealm()` does not work when removing the last object. This PR fixes the bug, and adds a number of unit tests.

@emanuelez @bmunkholm @cmelchior