rebuild logic