Add class support

Bugger, just noticed that I wrote this on top of the previous one rather than as a fresh branch. They should still both merge, or you can just cherry-pick 3478392.

Just a silly little one - feel free to merge or reject depending on where you are going with this. I've tried to write as understandably as possible. There is a note in the commit about DB structure which may be worth a thought.