refactor table creation