Changed implementation of hasClass to one with better performance, more than 100 times faster.