Generalized factory