Reset previousVal and improve classname handling