turn flask into factory pattern