Finish refactoring chap.9