This is an extract of a commit, minimally edited to ensure it compiles. Closes #663. Related to #197.