Implementing the factory pattern