Moving generating local classed to a function