Add test cases, including doubtful cases; other code changes