Refactoring of factory class