properly handle identifiers that appear thrice or more