Tests and fix for class toggling

Thanks. Added a comment.