function rebuild, now working