Added final cleanup to set leaf lengths.