Refactored entityFactory