Added  unit tests and cleaned up some code

Added unit tests of Entity class to test basic assumptions. Cleaned up problems highlighted by the tests and changed minor style issues.