improve code in factory, fix variant with complex type