fix rebuild logic