Fixes TypeError when removing nodes without ids that aren't selected

I noticed that it was impossible to remove nodes that aren't selected and also do not have an id. Wrote a test case exposing the bug and fixed it.