Added hasClass condition to addClass method