new fields in entity, minor fixes and refactoring