Ported the rebuild method