aded generic entity definition and bunch of refactorings