Handle groupref_exists. A bunch of little cleanup.