Add relevant tests from 1060 and related bug fixes
two more tests from #1060
Merge pull request #1548 from nden/tests-from-1060

tests from 1060