various cleanup
start re-implementing ref