Added Factory Pattern code