refactor factory