utils.rewriteIds, slight refactoring, should not have any functional changes