refactored factory