Fix Generate IDs function