Fix algorithm to produce nicer identifiers