new rebuild algorithm