made writeTable it's own function.