Refactor factories, unit tests