Tests and fix for class toggling

@winhamwr here is a comment.