finish ref() and rref() functions, update sub()