refactored code; fixed invalid table name and invalid column name bug