Refactoring id generation