fix indexing bugs in printing code.