add arg checking to factory function