A new implementation for reference types

Hacked together a new implementation for reference types. It's far from perfect, but at least this one woks.