Finish implementation of ref