Move some helper functions into factories
Add support for secondary source. Fixes #9