clean up subentity handling in 2.3

Ok, started off on latest 2.3 branch (v2.3.5). Works fine in current project.
Just cherry-picked 2 commits on master.