A more straightforward way to get the class

I’ve also added a test for this scenario.