Please pull out into a new method (something like writeEndTable()) to remove duplicate code.