More cleanups.
Fixed duplicate table bug.
Add test case for the table bug.