Improved logic for table cells.