This actually worked correctly, except for some assert() statements.
Check-in fixes those faulty
assert() statements so that everything is working now.

Test cases added to TH3.