Fix some bugs in Chapter 3, 4, 5