add writeTable() function