rewrote writeGrid(), etc.,