Clean up the factory code

Proposal to reduce the factory code