Simplify node ownership tracking, add pre-assert

The current code handles `p == 0` earlier, so it only sets `p` to null to break the loop and to detect that the node should be deleted. This can be simplified.