Changed clearing the table cells before the actual addition of classes.