Removed replaced code during refactoring. Added more tests. #1843 is complete, but fails after schema change, i.e., due bug.