Refactor the id changing stuff