Refactor rebuildAll method