Fix instruction printing bug and add unit tests.