refactor tail classes (though bugs remaining).
code cleanup.