Refactoring with factory method pattern