Convert to reference classes

Fixes #5. Fully functional for me in R versions 3.0.0 and 2.15.3.