Maybe move this class definition outside the function, so that it isn't re-executed each time the function is called.