finished chapter 4 of ISBN 9781783287031 + code cleanup