Refactored a lot of code for Entity and derived classes.

Hopefully nobody was working in those.  If you WERE, I recommend committing to a branch and I can merge it later.