Generate Table Improvements

Some improvments of table generation algorithm