Some refactoring, improved doc of entities, add "key" attribute.