ported factory to kotlin