Partial implementation of Ref with tests