table preparation refactored