Class implentation also fixes #41

@hijonathan @b-ash This is an alternative fix for #41.
I know this a big deviation in style, so it's a long shot, but what do you guys think?