stuff for chapter 6, not fully tested