gh-1221

not ready for merge yet - there are three separate (but related) issues in #1221, only one is fixed so far...