Changes according Dominic's notes:
- code formattinr
- for() loops replaced by forEach
- use assert_unreached