Replace factory method with factory function