optimize table generation