Improve hasClass function and tests