refactored factory class