Add some checks and change order of operation (update and remove)

In some situation (treenode test), there was problem with order of operation. So after change this order (first make updates and then removes) everythink seems to OK.

Next problem I have with collection which has been set to null value when doing cascade remove (treenode test), so I added condition test