Refactoring, fix issues on factory