Updated factory to use reflection instead of case statement.