improve id generation logic