refactoring factory method.

Not finished, but worth a pull request to backup code and show latest change to colleagues.