little more robust handling of references