refactor chp2 examples