Fix ambiguity aggregator bug. Add test cases for it.