improved CSS class rendering logic