refactor helper.writeTable