Changes invcode and tests for chapter 2

changes in codes and tests for chapter 2