Some refactoring as well as implementing Factory.