Refactor factory api