refactor table creation/cleanup.
incremental cleanup conditions.
add test for improved cleanup.