Fix leaf calculation