Introduction of PrimaryKey annotation and small refactoring