debug in rebuild function