Improvements to entity diffing code

Done by d3a05af