fix missing table variable, code clean up