This code should really be in a single function shared with the code above to check an identifier, and ensure it is unique.