improved rebuilding a bit