Minor tweak for class loading

Added some type safety in the class loading algorithm, while investigating #150. This isn't a fix for the bug, but it makes the code much saner.