Fix a bug with replacing root nodes

The fix (in Hquery.hs) is basically just to try to find the right-most inserted
node if possible, otherwise just return the current node. Previously we weren't
returning the current node, so the default (i.e. the empty node) was returned.

Also added some more tests.