refactor newid algo