Fix id generation for all cases