added factory pattern