more refactoring and begin of table generation