refactored and reorganized factories