it seems that class is superfluous here, why not just use nested function?