chap 3 almost completed: fixed #11, fixed #23, fixed #39