Merging code from ch 5 into prose & v-v
backported QEM chapter 5 to git