replaced direct class in instance creation

return new EntityManager() -> return new static() on line 945
made code more reusable