refactor table printing