chapter 6, to ex 6, reimplementing with `a better api state actions`