Implements factory pattern