A number of modifications to make the funcion demo more generic and abstract.