Fixed the incorrect rerooting procedure