More basic refactoring in ModifyEntity

Sorry for touching the same code again. I was to slow reviewing
I6cb0029 and did this instead. Plus a bunch of other changes that
hopefully make the code cleaner. Feel free to object if you think
one of the changes I made is not helpful.

Change-Id: Id2c05e4c69ded50beca1892dc9eac9f152b84a98