Optimize addClass method