A new implementation for reference types

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