more refactoring to use factories where possible