Figured out why Case 3 is too greedy. Fixed. Still left with some issues in Case 2.