finally fixed table code