Refactoring with factory and use stack builder