Cleanup chapter 1 solution

Remove dead code and simplify iteration.