added factory design pattern.