Chapter 5 refactored and committed.