Refactor for factory