Improvements to entity diffing code