Refine package installer for chapter 3 and reformat

Add checks before installing packages. Fix an issue of missing line
break. Replace all tabs with 4 spaces.