Refactor type id generator into utils.